package com.project.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.ExpertBean;
import com.project.dao.ExpertDao;
import com.project.service.ExpertService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 专家
 */
@Service
@Transactional
public class ExpertServiceImpl extends ServiceImpl<ExpertDao, ExpertBean> implements ExpertService {
    @Override
    public IPage<ExpertBean> findAllExpert(int pageNO, int pageSize) {
        Page<ExpertBean> page = new Page<>(pageNO, pageSize);
        IPage<ExpertBean> iPage = this.page(page);
        return iPage;
    }

    @Override
    public void addExpert(ExpertBean expertBean) {
        this.baseMapper.insert(expertBean);
    }

    @Override
    public ExpertBean findId(int expertId) {
        return this.baseMapper.findId(expertId);
    }

    @Override
    public void updateExpert(int expertId, String expertTel, String expertJop, String expertUnit, String expertEmail) {
        ExpertBean expertBean = new ExpertBean();
        expertBean.setExpertId(expertId);
        expertBean.setExpertTel(expertTel);
        expertBean.setExpertJop(expertJop);
        expertBean.setExpertUnit(expertUnit);
        expertBean.setExpertEmail(expertEmail);
        this.updateById(expertBean);
    }

    @Override
    public void delExpert(int expertId) {
        this.delExpert(expertId);
    }

    @Override
    public IPage<ExpertBean> findName(int pageNO, int pageSize, String expertName, String expertSpecialty, String expertUnit) {
        Page<ExpertBean> page = new Page<>(pageNO,pageSize);
        QueryWrapper wrapper = new QueryWrapper();
        if (expertName!=null && !expertName.equals("")){
            wrapper.like("expert_name",expertName);
        }
        if (expertSpecialty!=null && !expertSpecialty.equals("")){
            wrapper.like("expert_specialty",expertSpecialty);
        }
        if (expertUnit!=null && !expertUnit.equals("")){
            wrapper.like("expert_unit",expertUnit);
        }
        IPage<ExpertBean> iPage = this.page(page,wrapper);
        return iPage;
    }
}
